﻿using System;
using System.Windows.Forms;

namespace TAProject.UI.Service.Price
{
    public partial class FormPrice : FormTemplate
    {
        readonly private Form _parentForm;

        public decimal? Price {private set; get; }

        public FormPrice(Form parentForm)
            : base(parentForm)
        {
            InitializeComponent();

            _parentForm = parentForm;
            _parentForm.Enabled = false;
        }

        public FormPrice(Form parentForm, decimal price):this(parentForm)
        {
            textBoxPrice.Text = price.ToString();
        }

        private void ButtonSubmitClick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBoxPrice.Text))
            {
                try
                {
                    Price = decimal.Parse(textBoxPrice.Text.Replace(".", ","));
                    FormClose();
                }
                catch (Exception)
                {
                    MessageBox.Show("Введено некорректное значение.");
                }
            }else
            {
                MessageBox.Show("Введите цену.");
            }

        }

        private void FormClose()
        {
            _parentForm.Enabled = true;
            Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Price = null;
            FormClose();
        }
    }
}